<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>

</html>

<script>
    const canvas = document.createElement("canvas");
    canvas.width = 600;
    canvas.height = 400;
    document.body.append(canvas);
    const context = canvas.getContext("2d");


    let g = context.createLinearGradient(0, 0, 600, 0)

    g.addColorStop(0, 'red');
    g.addColorStop(0.25, 'yellow');
    g.addColorStop(0.5, 'orange');
    g.addColorStop(0.75, 'pink');
    g.addColorStop(1, 'purple');
    context.fillStyle = g;
    context.strokeStyle = g;

    // 使用fillStyle 和 strokeStyle
    // fillStyle 对应的是fill相关方法的颜色 反之 stroke对应的是stroke相关方法的颜色

    // h绘制文字 italic斜体
    context.font = 'italic 50px Arial';
    context.fillText('helloword.cn', 200, 100);
    context.strokeText('wolfcode.cn', 300, 200);


</script>